<template>
    <div>
        <div class="content release matchDetail">
            <heading grade="2" style="margin-top:0">赛事基本信息</heading>
            <el-form  v-bind="getFormProps()"  novalidate="novalidate"  :rules="rules" ref="form" label-width="134px">
                <el-form-item label="运动类型：">
                    <span>{{form.matchTypeStr}}</span>
                </el-form-item>
                <el-form-item label="赛事名称："
                              prop="matchName"
                              :rules="[
                   { required: true, message: '赛事名称不能为空'},
                 ]">
                    <el-input v-model.trim="form.matchName"
                              placeholder="请输入赛事名称"></el-input>
                </el-form-item>
                <el-form-item label="赛事logo："
                              prop="logoUrl"
                              :rules="[
                   { required: true, message: '请上传赛事Logo'},
                 ]">
                    <img-upload v-model="form.logoUrl" class="logo-upload"/>
                    <span class="form-help">(单张照片不超过5MB)</span>
                </el-form-item>
                <el-form-item label="赛事推荐图APP："
                              prop="matchImgApp"
                              :rules="[
                   { required: true, message: '请上传app赛事推荐图'},
                 ]">
                    <img-upload v-model="form.matchImgApp" class="logo-upload"/>
                    <span class="form-help">(单张照片不超过5MB)</span>
                </el-form-item>
                <el-form-item label="赛事推荐图PC："
                              prop="matchImgPc"
                              :rules="[
                   { required: true, message: '请上传赛事推荐图PC'},
                 ]">
                    <img-upload v-model="form.matchImgPc" class="logo-upload"/>
                    <span class="form-help">(单张照片不超过5MB)</span>
                </el-form-item>
                <el-form-item label="所在地区："
                              prop="area"
                              :rules="[
                   { required: true, message: '请选择省份'},
                 ]">
                    <address-cascader v-if="form.area.length" v-model="form.area" :grade="2"/>
                </el-form-item>
                <el-form-item label="报名时间："
                              prop="signDate"
                              :rules="[
                   { required: true, message: '请选择比赛时间,报名开始的时间与报名截止的时间必须相差至少3天'},
                 ]">
                    <el-date-picker
                            v-model="signDate"
                            type="daterange"
                            placeholder="选择报名日期"
                            :picker-options="pickerOptions0"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="比赛时间："
                              prop="matchDate"
                              :rules="[
                   { required: true, message: '请选择比赛时间,比赛的开始时间须比报名的截止时间晚至少24小时'},
                 ]">
                    <el-date-picker
                            v-model="matchDate"
                            type="daterange"
                            placeholder="选择比赛日期"
                            :picker-options="pickerOptions1"
                    >
                    </el-date-picker>
                </el-form-item>

                <heading grade="2">参赛相关信息</heading>
                <el-form-item label="竞技水平：" v-if="!isRun">
                    <el-radio-group v-model="form.sportingLevel">
                        <el-radio v-for="item in requirement[21]"
                                  :label="item.fieldValue" :key="item.fieldValue" >{{item.fieldName}}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="参赛者要求：">
                  <el-radio-group  v-model="form.joinRequire">
                      <el-radio v-for="item in requirement[20]"
                                :key="item.fieldValue" :label="item.fieldValue">{{item.fieldName}}
                      </el-radio>
                  </el-radio-group>
                </el-form-item>

                <el-form-item v-if="isGroupGame && (form.joinRequire==20002||form.joinRequire==20004 )" label="参赛球队数量："
                              prop="joinNumber"
                              :rules="{ required: true, type: 'number',min:4, message: '请输入参赛球队数量且大于等于4'}">
                    <el-input-number :min="4" :max="128" v-model.number="form.joinNumber" placeholder="请输入球队数量"></el-input-number>
                    <span class="form-help">(数量≥4)</span>
                </el-form-item>
                <template v-else>
                  <el-form-item v-if="form.joinRequire%2 == 1 " label="参赛者数量："
                                prop="joinNumber"
                                :rules="{ required: true, type: 'number',min:4, message: '请输入参赛者数量且大于等于4'}">
                      <el-input-number :min="4" :max="128" v-model.number="form.joinNumber" placeholder="请输入参赛者数量"></el-input-number>
                      <span class="form-help">(数量≥4)</span>
                  </el-form-item>
                  <el-form-item v-else label="参赛组合数量："
                                prop="joinNumber"
                                :rules="{ required: true, type: 'number',min:4, message: '请输入参赛组合数量且大于等于4'}">
                      <el-input-number :min="4" :max="128" v-model.number="form.joinNumber" placeholder="请输入参赛组合数量"></el-input-number>
                      <span class="form-help">(数量≥4)</span>
                  </el-form-item>
                </template>

                <el-form-item label="报名审核：">
                    <el-radio-group v-model="form.signChecked">
                        <el-radio v-for="item in reviewList" :key="item.value" :label="item.value">
                            {{item.label}}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="是否摇号：" v-if="isRun">
                    <el-radio-group v-model="form.lottery">
                        <el-radio v-for="item in isRoll"
                                  :key="item.value" :label="item.value">{{item.label}}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="摇号轮次：" v-if="isRun&&form.lottery==1">
                    <el-input-number placeholder="请输入摇号轮次" v-model="form.channelsRound" :min="0" :max="6"></el-input-number>
                </el-form-item>


                <el-form-item label="赛制人数：" v-if="!isRun">
                    <el-radio-group  v-model="form.formatNumberType">
                        <el-radio v-for="item in requirement[23]" :key="item.fieldName" :label="item.fieldValue">{{item.fieldName}}</el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item v-if="isGroupGame" label="每队报名人数："
                              prop="playerNumber"
                              :rules="[
                    { required: true, message: '请输入每队报名人数'},
                      ]">
                    <el-input-number  :min="3" :max="23" v-model.number="form.playerNumber" placeholder="请输入每队报名人数"></el-input-number>
                </el-form-item>

                <el-form-item label="设置组别：">
                    <el-checkbox-group v-model="form.groupTypeList"      :min="1">
                        <el-checkbox v-for="item in requirement[22]" :label="item.fieldName" :key="item.fieldValue">{{item.fieldName}}</el-checkbox>
                    </el-checkbox-group>
                </el-form-item>

                <el-form-item v-if="isRun" label="报名渠道："
                 prop="matchChannelsList"
                  :rules="[
                  { required: true, message: '请选择赛制类型'},
                  Object.assign({}, validator.rule.NumberArray,{message: '请输入渠道名额，名额为正整数'})
                  ]">
                  <div v-for="(item,index) in form.matchChannelsList" :key="item" class="mb10">
                    <el-row class="mb10" >
                      <el-input class="input-middle" placeholder="请输入报名渠道名称"  v-model.trim="item.channelName" :readonly="index==0"></el-input>
                      <el-button class="btn-icon" icon="minus" v-if="index>0" @click="delChannel(index)"></el-button> 
                    </el-row>
                    <el-row>
                      <el-col :span="6"  v-for="(it,$index) in item.channelsGroup" :key="it" >
                          <label>{{it.groupDes}}：</label>
                          <el-input-number style="width:100px" :debounce="0" :max="999999" placeholder="输入名额" v-model="it.lotteryNumbers"></el-input-number>
                      </el-col>
                    </el-row>
                  </div>    
                  <el-button class="btn-icon" icon="plus" @click="addChannel()" :disabled="form.matchChannelsList.length>=6"></el-button>              
                </el-form-item>

                <el-form-item label="赛制类型："
                              prop="matchFormat"
                              :rules="[
                 { required: true, message: '请选择赛制类型'},
                ]">
                    <el-select v-model="form.matchFormat" placeholder="请选择" class="input-small">
                        <el-option
                                v-for="item in requirement[24]"
                                :key="item.fieldValue"
                                :label="item.fieldName"
                                :value="item.fieldValue">
                        </el-option>
                    </el-select>
                    <!--
                    <template v-if="!isGroupGame&& !isRun">
                      <el-select  v-model="form.matchNum" placeholder="请选择" class="input-small">
                        <el-option
                                v-for="item in matchNumList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                      </el-select>
                      <el-select v-model="form.pointNum" placeholder="请选择" class="input-small">
                        <el-option
                                v-for="item in pointList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>   
                    </template>
                    
                    <template v-if="type=='网球'">
                      <el-select  v-model="form.matchNum" placeholder="请选择" class="input-small">
                          <el-option
                                  v-for="item in tennisGameNumList"
                                  :key="item.value"
                                  :label="item.label"
                                  :value="item.value">
                          </el-option>
                      </el-select>
                      <el-select v-model="form.preemption" placeholder="请选择" class="input-small">
                        <el-option
                                v-for="item in preeList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                      </el-select>
                    </template>
                    -->
                    
                                     
                    <span class="form-help" v-if="type=='羽毛球'">(最多可设置2个阶段)</span>
                </el-form-item>

                <el-form-item label="是否有保险：">
                    <el-radio-group v-model="form.insuranced">
                        <el-radio v-for="item in insuranceList" :key="item.value" :label="item.value">{{item.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="报名费用：">
                  <el-radio-group v-model="form.cost">
                      <el-radio  :label="0">免费</el-radio>
                      <el-radio  :label="1">收费</el-radio>
                  </el-radio-group>
                  <div v-if="!isRun">
                      <el-input-number v-model="form.groupMoneyList[0]" v-show="form.cost==1" placeholder="请输入金额"></el-input-number>
                      <span v-show="form.cost==1">元</span>
                  </div>
                  <div v-if="isRun&&form.cost==1">
                      <el-row style="margin-bottom:10px;">
                          <el-col :span="12" v-for="item in form.moneyList" :key="item" >
                              <label class="run-type">{{item.fieldName}} </label>
                              <el-input-number class="input-small" placeholder="请输入费用" v-model="item.value"></el-input-number>元
                          </el-col>
                      </el-row>
                  </div>
                </el-form-item>
                <el-form-item label="支付限时：" v-if="form.cost == 1">
                    <el-input-number v-model="form.payTime" :min="1" :max="99" class="input-small"></el-input-number>小时
                </el-form-item>

                <div v-if="isRun">
                    <el-form-item label="快递参赛包：">
                        <el-radio-group v-model="form.express">
                            <el-radio v-for="item in expressBag" :key="item.value" :label="item.value">
                                {{item.label}}
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="衣服尺寸：">
                        <el-radio-group v-model="form.clothingSize">
                            <el-radio v-for="item in clothSize" :key="item.value" :label="item.value">{{item.label}}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="紧急联系人：">
                        <el-radio-group v-model="form.emergencyContact">
                            <el-radio v-for="item in needContactor" :key="item.value" :label="item.value">
                                {{item.label}}
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>

                <heading grade="2">其他信息</heading>
                <el-form-item label="联系人："
                              prop="linkMan"
                              :rules="[
                   { required: true, message: '请输入联系人'},
                 ]">
                    <el-input :maxlength="20" v-model.trim="form.linkMan" placeholder="请输入联系人姓名"></el-input>
                </el-form-item>
                <el-form-item label="联系方式："
                              prop="contactWay"
                              :rules="[
                   { required: true, message: '请输入联系方式'},
                 ]">
                    <el-input :maxlength="16" v-model="form.contactWay" placeholder="请输入联系方式"></el-input>
                </el-form-item>
                <el-form-item label="赛事详情："
                  prop="matchDetails"
                  :rules="[
                  { required: true, message: '请输入赛事详情'}
                  ]">
                   <editor v-model="form.matchDetails" :maxlength="500" @change="$refs.form.validateField('matchDetails')"/> 
                </el-form-item>
                <el-form-item label="主办单位"
                  prop="sponsorsList"
                  :rules="[
                  { required: true, message: '请输入主办单位名称'},
                  Object.assign({}, validator.rule.orgArray,{message: '单位名称字符应在2~30个字符'})
                ]">
                    <input-group :maxlength="30" placeholder="请输入主办单位名称" :max-item="6" v-model="form.sponsorsList"></input-group>
                </el-form-item>
                <el-form-item label="承办单位"
                  prop="organizersList"
                  :rules="[
                  { required: true, message: '请输入承办单位名称'},
                  Object.assign({}, validator.rule.orgArray,{message: '单位名称字符应在2~30个字符'})
                ]">
                    <input-group :maxlength="30" placeholder="请输入承办单位名称" :max-item="6" v-model="form.organizersList"></input-group>
                </el-form-item>
                <el-form-item label="协办单位"
                  prop="corganizersList"
                  :rules="[                 
                    Object.assign({}, validator.rule.coOrgArray,{message: '单位名称字符应在2~30个字符'})
                  ]">
                    <input-group :maxlength="30" placeholder="请输入协办单位名称" :max-item="6" v-model="form.corganizersList"></input-group>
                </el-form-item>
                <el-form-item label="赛事配图："
                              prop="matchImagesList"
                              :rules="[
                   { required: true, message: '请上传赛事配图'},
                 ]">
                    <div class="form-help" >上传赛事相关图片（单张图片不超过5MB，支持jpg，png，gif格式）</div>
                    <img-group-upload v-model="form.matchImagesList" :limit="10" />
                    <div class="form-help" >(最多支持上传10张,轮播的形式)</div>
                </el-form-item>
                <div class="button-box">
                    <el-button type="primary" native-type="submit">提交</el-button>
                </div>
            </el-form>
        </div>
    </div>
</template>

<script>
  import AddressCascader from '../components/AddressCascader'
  import InputGroup from '../components/InputGroup'
  import ImgUpload from '../components/ImgUpload'
  import ImgGroupUpload from '../components/ImgGroupUpload'
  import Editor from '../components/Editor'
  import constant from './constant'
  import raceApi from 'api/race'
  import { mapGetters } from 'vuex'
  import validator from 'utils/validator'
  import {cloneObj, dateToTimestamp, getDateDiff, addDate} from 'utils/index'
  import {form} from 'utils/mixins'
  export default {
    mixins: [form],
    components: {
      AddressCascader,
      InputGroup,
      ImgUpload,
      Editor,
      ImgGroupUpload
    },
    computed: {
      ...mapGetters({
        global: 'global',
        race_detail: 'race_detail',
        userId: 'userId'
      }),
      // 是否是团队运动（足球、篮球）， (羽毛球、网球、乒乓球视为个人运动)
      isGroupGame () {
        return this.race_detail.matchType === 3001 || this.race_detail.matchType === 3002
      },
      isDouble () {
        return this.form.joinRequire
      },
      isRun () {
        return this.race_detail.matchType === 3006
      },
      type () {
        return this.race_detail.matchTypeStr
      },
      signDate: {
        set (value) {
          this.form.signDate = value && value[0] ? value : ''
        },
        get () {
          return this.form.signDate
        }
      },
      matchDate: {
        set (value) {
          this.form.matchDate = value && value[0] ? value : ''
        },
        get () {
          return this.form.matchDate
        }
      },
      signEndDate () {
        return this.form.signDate[1]
      }
    },
    created () {
      // console.log(this.$route)
    },
    mounted () {
      this.getRequire()
    },
    watch: {
      // 监听路由变化拉取参赛者要求信息
      '$route': 'getRequire',
      'isDouble': 'getMatchFormatNumberByParent'
    },
    data () {
      return {
        validator,
        pickerOptions0: {
          disabledDate (time) {
            return time.getTime() < Date.now() - 8.64e7
          }
        },
        pickerOptions1: {
          disabledDate (time) {
            return time.getTime() < new Date(addDate(self.signEndDate, 3)).getTime() - 8.64e7
          }
        },
        rules: {},
        numberTempList: [],
        groupList: [], // 组别列表
        form: {
          isEdit: true,
          id: '',
          userId: this.userId,
          matchType: 0,   // 比赛类型
          matchFormat: 24001, // 赛制类型
          matchNum: null,    // 比赛盘数
          matchName: '',   // 赛事名称
          pointNum: null,   // 比赛每盘比分
          logoUrl: '',
          matchImgPc: '',
          matchImgApp: '',
          area: [], // 省市区
          provinceId: this.provinceId,
          cityId: this.cityId,
          startTime: '',  // 比赛日期
          endTime: '',
          matchDate: '',
          signStartTime: '',
          signEndTime: '',
          signDate: '',     // 报名日期
          sportingLevel: 21015,   // 竞技水平
          joinRequire: 20001,    // 参赛者要求
          lottery: 1,       // 是否摇号
          channelsRound: 1,     // 摇号轮次
          matchChannelsList: [
            {
              channelName: '求苗',
              channelsGroup: []
            }
          ], // 报名渠道
          channelsNumberList: [], // 渠道名额
          joinNumber: 0,      // 参赛球队数量
          preemption: null,   // 是否有占先
          signChecked: 1,        // 报名是否需要审核
          formatNumberType: 1,     // 赛制人数
          playerNumber: 0,   // 每队报名人数
          groupTypeList: [],  // 组别
          insuranced: 1,    // 是否有保险
          cost: 1,         // 收费或免费
          moneyList: [],
          groupMoneyList: [], // 球类收费
          groupTypeMoneyList: [],  // 跑步收费
          express: 1, // 快递参赛包
          clothingSize: 1, // 衣服尺寸
          emergencyContact: 1, // 是否需要紧急联系人
          payTime: 1,  // 支付限时
          linkMan: '', // 联系人
          contactWay: '',  // 联系方式
          remarks: '',  // 备注
          matchDetails: '', // 赛事详情
          sponsorsList: [], // 主办单位
          organizersList: [], // 承办单位
          corganizersList: [], // 协办单位
          matchImagesList: [],
          status: 0,
          drawsState: 0 // 签表状态 0：未生成，1：草稿：2已生成,3已创建赛程
        },
        requirement: {},
        imageUrl: '',
        ...constant
      }
    },
    methods: {
      timeFormat () {
        this.form.startTime = dateToTimestamp(this.form.startTime)
        this.form.endTime = dateToTimestamp(this.form.endTime)
        this.form.signStartTime = dateToTimestamp(this.form.signStartTime)
        this.form.signEndTime = dateToTimestamp(this.form.signEndTime)
      },
      // 手动验证日期是否符合规则
      customValid () {
        this.formatData()
        let message
        let isSuccess = true
        let d = new Date()
        if (dateToTimestamp(this.form.signStartTime) < dateToTimestamp(d) - 86400000) {
          message = '报名时间不能小于当前时间'
          isSuccess = false
        }
        if (dateToTimestamp(this.form.startTime) < dateToTimestamp(d)) {
          message = '比赛时间不能小于当前时间'
          isSuccess = false
        }
        if (getDateDiff(this.form.signEndTime, this.form.signStartTime) < 3) {
          message = '报名结束日期必须比报名开始日期晚3天'
          isSuccess = false
        }
        if (dateToTimestamp(this.form.startTime) < dateToTimestamp(this.form.signEndTime)) {
          message = '比赛开始日期必须比报名结束日期晚1天'
          isSuccess = false
        }
        if (this.form.matchImagesList.length > 10) {
          message = '最多上传10张赛事配图'
          isSuccess = false
        }
        if (this.form.cost && (this.gameId !== 3006) && this.form.groupMoneyList[0] <= 0) {
          message = '报名费用需大于0'
          isSuccess = false
        }
        if (this.form.cost && this.gameId === 3006) {
          for (var i = 0, len = this.form.moneyList.length; i < len; i++) {
            if ((this.form.groupTypeList.indexOf(this.form.moneyList[i].fieldName) > -1) && this.form.moneyList[i].value <= 0) {
              message = '报名费用需大于0'
              isSuccess = false
              break
            }
          }
        }
        if (!isSuccess) {
          return {
            isSuccess: false,
            errMsg: message
          }
        } else {
          return {
            isSuccess: true
          }
        }
      },
      // 根据父类拉取赛制类型
      getMatchFormatNumberByParent () {
        if (!this.isGroupGame && !this.isRun) { // 羽毛球，网球，乒乓球
          raceApi.getMatchFormatNumberByParent({parentValue: this.form.joinRequire}, this).then((res) => {
            this.requirement[23] = res.data
          })
        }
      },
      // 获取参赛相关信息
      getRequire () {
        if (this.isRun) { // 跑步
          raceApi.runRequirement({matchType: this.race_detail.matchType}, this).then((res) => {
            let json = JSON.stringify(res.data[22])
            this.groupList = this.requirement[22]
            this.requirement = res.data
            this.form.moneyList = JSON.parse(json) // 深拷贝
            this.numberTempList = []
            this.requirement[22].forEach(i => {
              this.numberTempList.push({
                groupDes: i.fieldName,
                lotteryNumbers: 0
              })
            })
            this.form.matchChannelsList[0].channelsGroup = JSON.parse(JSON.stringify(this.numberTempList))
            this.form.moneyList.forEach(function (j) {
              j.value = ''
            })
            this.setMatchInfo()
          })
        } else { // 球类
          raceApi.requirement({matchType: this.race_detail.matchType}, this).then((res) => {
            this.requirement = res.data
            this.groupList = this.requirement[22]
            this.groupTypeMoneyList = ['']
            this.setMatchInfo()
          })
        }
      },
      // 设置赛事信息
      setMatchInfo () {
        let form = this.form
        let detail = this.race_detail
        form.id = detail.id
        form.matchType = detail.matchType
        form.matchTypeStr = detail.matchTypeStr
        form.matchName = detail.matchName
        form.logoUrl = detail.logoUrl
        form.matchImgApp = detail.matchImgApp
        form.matchImgPc = detail.matchImgPc
        form.area[0] = detail.provinceId
        form.area[1] = detail.cityId
        form.playerNumber = detail.playerNumber
        if (detail.matchImagesList.length) {
          form.matchImagesList = detail.matchImagesList
        }
        this.signDate = [new Date(detail.signStartTime), new Date(detail.signEndTime)]
        this.matchDate = [new Date(detail.startTime), new Date(detail.endTime)]
        // 参赛相关信息
        form.joinRequire = detail.joinRequire
        form.sportingLevel = detail.sportingLevel
        form.joinNumber = detail.joinNumber
        form.signChecked = detail.signChecked // 审核
        form.lottery = detail.lottery // 是否摇号
        if (this.isRun) {
          if (detail.groupTypeList && detail.groupTypeList.length) { // 设置渠道报名费用的label
            form.groupTypeList = []
            if (this.requirement && this.requirement[22].length) {
              for (var i = 0, len = this.requirement[22].length; i < len; i++) { // eslint-disable-line
                for (var j = 0, jlen = detail.groupTypeList.length; j < jlen; j++) { // eslint-disable-line
                  if (this.requirement[22][i].fieldValue == detail.groupTypeList[j].groupType) { // eslint-disable-line
                    form.groupTypeList[i] = this.requirement[22][i].fieldName
                  }
                }
              }
            }
          }
          if (detail.matchChannelsList && detail.matchChannelsList.length) { // 设置渠道信息
            form.matchChannelsList = detail.matchChannelsList
          }
          if (detail.groupTypeList && detail.groupTypeList.length) { // 报名费用
            for (let n = 0, nlen = this.requirement[22].length; n < nlen; n++) {
              form.moneyList[n].value = detail.groupTypeList[n] ? detail.groupTypeList[n].groupMoney : 0
            }
          }
        } else { // 球类
          detail.groupTypeList && detail.groupTypeList.forEach(item => { // 设置组别
            form.groupTypeList.push(item.groupTypeStr)
            form.groupMoneyList[0] = item.groupMoney
          })
        }
        form.formatNumberType = detail.formatNumberType
        form.matchFormat = detail.matchFormat
        form.cost = detail.cost
        form.payTime = detail.payTime
        form.express = detail.express
        form.clothingSize = detail.clothingSize
        form.emergencyContact = detail.emergencyContact
        // 其他信息
        form.linkMan = detail.linkMan
        form.contactWay = detail.contactWay
        form.remarks = detail.remarks
        form.matchDetails = detail.matchDetails || detail.remarks
        form.sponsorsList = detail.sponsorsList.length ? detail.sponsorsList : []
        form.organizersList = detail.organizersList.length ? detail.organizersList : []
        form.corganizersList = Array.isArray(detail.corganizersList) ? detail.corganizersList : ['']
      },
      submit () {
        this.customValid()
        this.timeFormat()
        var formData
        if (this.isRun) {
          this.formatRunData()
          formData = cloneObj(this.form)
          raceApi.releaseRun(formData, {context: this}).then((res) => {
            this.handleSubmitSuccess()
          }).catch((err) => {
            console.log(err)
          })
        } else {
          formData = cloneObj(this.form)
          raceApi.release(formData, {context: this}).then((res) => {
            this.handleSubmitSuccess()
          }).catch((err) => {
            console.log(err)
          })
        }
      },
      // 格式化跑步数据
      formatRunData () {
        var form = this.form
        form.groupTypeMoneyList = []
        form.moneyList.forEach(item => { // 报名费用
          if (form.groupTypeList.indexOf(item.fieldName) > -1) {
            form.groupTypeMoneyList.push(item.value)
          }
        })
        var result = []
        this.requirement[22].forEach(item => { // 输入选中的组别
          if (form.groupTypeList.indexOf(item.fieldName) > -1) {
            result.push(item.fieldValue)
          }
        })
        form.groupTypeList = result
        var mList = []
        var groupLength = this.requirement[22].length
        for (var i = 0, len = this.form.matchChannelsList.length; i < len; i++) {
          mList.push({
            channelName: this.form.matchChannelsList[i].channelName,
            channelsGroup: [
              {groupType: this.requirement[22][0].fieldValue, groupDes: this.requirement[22][0].fieldName, lotteryNumbers: 0},
              {groupType: this.requirement[22][1].fieldValue, groupDes: this.requirement[22][1].fieldName, lotteryNumbers: 0},
              {groupType: this.requirement[22][2].fieldValue, groupDes: this.requirement[22][2].fieldName, lotteryNumbers: 0},
              {groupType: this.requirement[22][3].fieldValue, groupDes: this.requirement[22][3].fieldName, lotteryNumbers: 0}
            ]
          })
          for (var j = 0; j < groupLength; j++) {
            mList[i].channelsGroup[j].lotteryNumbers = this.form.matchChannelsList[i].channelsGroup[j].lotteryNumbers
          }
        }
        this.form.matchChannelsList = mList
      },
      handleSubmitSuccess () {
        this.$router.push({path: '/race/release'})
      },
      // 格式化提交数据
      formatData () {
        this.form.userId = this.userId
        this.form.provinceId = this.form.area[0] || ''
        this.form.cityId = this.form.area[1] || ''
        if (this.form.matchDate.length) {
          this.form.startTime = new Date(this.form.matchDate[0]).format()
          this.form.endTime = new Date(this.form.matchDate[1]).format()
        }
        if (this.form.signDate.length) {
          this.form.signStartTime = new Date(this.form.signDate[0]).format()
          this.form.signEndTime = new Date(this.form.signDate[1]).format()
        }
        if (!this.isRun) {
          var groups = this.form.groupTypeList.concat() // 复制一份已选组别
          this.form.groupTypeList = []
          let money = this.form.groupMoneyList[0]
          this.form.groupMoneyList = []
          groups.forEach(item1 => {
            this.requirement[22].forEach(item2 => {
              if (item1 == item2.fieldName) { // eslint-disable-line
                this.form.groupTypeList.push(item2.fieldValue)
                this.form.groupMoneyList.push(money)
              }
            })
          })
        }
      },
      // 增加渠道
      addChannel () {
        if (this.form.matchChannelsList.length >= 6) {
          return
        }
        this.form.matchChannelsList.push({
          channelName: '',
          channelsGroup: JSON.parse(JSON.stringify(this.numberTempList))
        })
      },
      delChannel (index) {
        this.form.matchChannelsList.splice(index, 1)
      }
    }
  }
</script>

<style lang="scss" scoped>
    .select-group {
        .el-select {
            width: 150px;
        }
    }

    .logo-upload {
        width: 160px;
        height: 90px;
    }

    .fee-input {
        width: 110px;
        margin: 0 5px;
    }

    .run-type {
        width: 50px;
        text-align: right;
        display: inline-block;
    }

    .small-input {
        width: 100px;
        margin-left: 5px;
    }

    .normal-input {
        width: 290px;
    }
</style>
